<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>用户列表</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="/resources/css/base.css" rel="stylesheet"
	type="text/css" />
<link href="/resources/js/miniui/themes/default/miniui.css"
	rel="stylesheet" type="text/css" />
<script src="/resources/js/jquery-1.6.2.min.js"
	type="text/javascript"></script>
<script src="/resources/js/miniui/miniui.js"
	type="text/javascript"></script>
<script src="/resources/js/ajaxfileupload.js" 
	type="text/javascript"></script>
<style type="text/css">
.errorText {
	color: red;
}
#editWindow {top: 50px !important;left:250px!important}
.mini-checkboxlist-item{    float: left;}
</style>
</head>
<body>
	<h1>人才库列表</h1>
	<div style="padding-top: 5px; padding-bottom: 5px; width: 95%;">
		<a class="mini-button"
			img="/resources/js/miniui/themes/icons/add.gif"
			onclick="load4add()">添加</a> 
		<a class="mini-button"
			img="/resources/js/miniui/themes/icons/edit.gif"
			onclick="editRow()">修改</a> 
		<a class="mini-button"
			img="/resources/js/miniui/themes/icons/remove.gif"
			onclick="delRow()">删除</a> 	
	</div>
	<div id="mini-datagrid" class="mini-datagrid"
		style="width: 95%; height: 400px;"
		url="/personnel/selectByPage" pageSize="20" idField="id"
		allowResize="true">

		<div property="columns">
			<div type="indexcolumn">序号</div>
			<div type="checkcolumn">选择</div>
			<div field="realname">真实姓名</div>
			<div field="sex">性别</div>
			<div field="idNo">身份证号码</div>
			<div field="diplomaName">证书名称</div>
			<div field="lastTime">毕业时间</div>
			<div field="flag">是否推荐</div>
		</div>
	</div>


	<div id="editWindow" class="mini-window" title="添加人才"
		style="width: 400px;" showModal="true" allowResize="true"
		allowDrag="true">
		<div id="editform" class="form" enctype="multipart/form-data">
			<input class="mini-hidden" name="id" value="0" />
			<table style="width: 100%; text-align: center;">
				<tr>
					<td style="width: 30%; text-align: right;">姓名：</td>
					<td style="width: 60%; text-align: left;">
						<input name="realname" class="mini-textbox" />
					</td>
					<td style="width: 10%;" id="realname_error" class="errorText"></td>
				</tr>
				<tr>
					<td style="width: 30%; text-align: right">性别：</td>
					<td style="width: 60%; text-align: left;">
						<input name="sex" class="mini-radiobuttonlist" data="[{id: 1, text: '男'}, {id: 2, text: '女'}]"/>
					</td>
					<td style="width: 10%;" id="diplomaImg_error" class="errorText"></td>
				</tr>					
				<tr>
					<td style="width: 30%; text-align: right">身份证号码：</td>
					<td style="width: 60%; text-align: left;">
						<input name="idNo" class="mini-textbox" />
					</td>
					<td style="width: 10%;" id="idNo_error" class="errorText"></td>
				</tr>
				<tr>
					<td style="width: 30%; text-align: right;">证书名称：</td>
					<td style="width: 60%; text-align: left;">
						<input name="diplomaName" class="mini-textbox" />
					</td>
					<td style="width: 10%;" id="diplomaName_error" class="errorText"></td>
				</tr>
				<tr>
					<td style="width: 30%; text-align: right;">毕业时间：</td>
					<td style="width: 60%; text-align: left;">
						<input name="lastTime" class="mini-textbox" />
					</td>
					<td style="width: 10%;" id="lastTime_error" class="errorText"></td>
				</tr>
				<tr>
					<td style="width: 30%; text-align: right">是否推荐：</td>
					<td style="width: 60%; text-align: left;">
						<input name="flag" class="mini-radiobuttonlist" data="[{id: 1, text: '是'}, {id: 2, text: '否'}]"/>
					</td>
					<td style="width: 10%;" id="diplomaImg_error" class="errorText"></td>
				</tr>				
				<tr>
					<td
						style="text-align: center; padding-top: 5px; padding-right: 20px;"
						colspan="3"><a class="mini-button"
						img="/resources/js/miniui/themes/icons/save.gif"
						onclick="saveBaseRow()">保存</a> <a class="mini-button"
						img="/resources/js/miniui/themes/icons/cancel.gif"
						onclick="cancelRow()">取消</a></td>
				</tr>
			</table>
		</div>
	</div>

</body>
<script type="text/javascript">
	mini.parse();
	var datagrid = mini.get("mini-datagrid");
	var editWindow = mini.get("editWindow");
	
	var form = new mini.Form("editform");
	var actionType = "insertPersonnel";
	datagrid.load();
	
	function load4add() {
		actionType = "insertPersonnel";
		editWindow.show();
		form.clear();
	}

	function saveBaseRow() {
		var json = form.getData();
		if (!validation(json))
			return;
		
		saveRow(json);
	}
	
	function cancelRow() {
		datagrid.reload();
		editWindow.hide();
	}
	
	
    function ajaxFileUpload() {
        
        var inputFile = $("#file1 > input:file")[0];

        $.ajaxFileUpload({
            url: '/personnel/fileupload',             //用于文件上传的服务器端请求地址
            fileElementId: inputFile,           //文件上传域的ID
            dataType: 'text',                   //返回值类型 一般设置为json
            success: function (data, status)    //服务器成功响应处理函数
            {
            	console.log(data);
                alert("上传成功: " + data);

            },
            error: function (data, status, e)   //服务器响应失败处理函数
            {
                alert(e);
            },
            complete: function () {
                var jq = $("#file1 > input:file");
                console.log(jq);
                jq.before(inputFile);
                jq.remove();
            }
        });
    }
    
	function saveRow(json) {

		//ajaxFileUpload();
		
		$.ajax({
			url : "/personnel/" + actionType,
			data : json,
			type : "post",
			dataType : "json",
			success : function(data) {
				if(data.code == 0){
					editWindow.hide();
					datagrid.reload();
					resetPwdwindow.hide();
					resetDealPwdwindow.hide();
				}else{
					mini.alert(data.data);
				}
			},
			error : function(jqXHR, textStatus, errorThrown) {
				alert(jqXHR.responseText);
			}
		});

	}	
	
	function validation(data) {
		if (data.id == 'undefined' || data.id == '') {
			data.id = 0;
		}
		
		if (data.realname == '') {
			$('#realname_error').html("真实姓名不能为空");
			return false;
		} else {
			$('#realname_error').html("");
		}

		if (data.idNo == '') {
			$('#idNo_error').html("身份证号码不能为空");
			return false;
		} else {
			$('#idNo_error').html("");
		}

		if (data.diplomaName == '') {
			$('#diplomaName_error').html("证书名称不能为空");
			return false;
		} else {
			$('#diplomaName_error').html("");
		}
		
		if (data.diplomaImg == '') {
			$('#diplomaImg_error').html("证书图片不能为空");
			return false;
		} else {
			$('#diplomaImg_error').html("");
		}		

		return true;
	}	
	
	function editRow() {

		var node = datagrid.getSelected();
		if (node) {
			actionType = "updatePersonnel";
			editWindow.show();
			form.clear();
			
			$.ajax({
				url : "/personnel/getById",
				data : {id:node.id},
				type : "post",
				dataType : "json",
				success : function(data) {
					form.setData(node);	
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});			
		} else {
			mini.alert("请选择一条!");
		}
	}	
	
	function delRow() {

		var node = datagrid.getSelected();
		if (node) {
			mini.confirm("确定删除！", "提示", function(retCode) {
				console.log(retCode);
				if (retCode == 'ok') {
					
					$.ajax({
						url : "/personnel/deletePersonnel",
						data : {
							id : node.id
						},
						type : "post",
						dataType : "json",
						success : function() {
							editWindow.hide();
							datagrid.reload();
						},
						error : function(jqXHR, textStatus, errorThrown) {
							alert(jqXHR.responseText);
						}
					});

				}
			})
		} else {
			mini.alert("请选择一条!");
		}
	}	
</script>

</html>
